package cn.highedu.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 英雄类
 */
@Component
public class Hero {
    @Value("亚瑟")
    private String name;
    @Autowired // 依赖注入 向Spring容器中查找对象名是roles的对象 如果有就注入
    private List<String> roles;
    @Autowired
    private Map<String, String> skills;
    @Autowired(required = false) // required = false 可以注入一个null值
    private Armor armor;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getRoles() {
        return roles;
    }

    public void setRoles(List<String> roles) {
        this.roles = roles;
    }

    public Map<String, String> getSkills() {
        return skills;
    }

    public void setSkills(Map<String, String> skills) {
        this.skills = skills;
    }

    public Armor getArmor() {
        return armor;
    }

    public void setArmor(Armor armor) {
        this.armor = armor;
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", roles=" + roles +
                ", skills=" + skills +
                ", armor=" + armor +
                '}';
    }

    public void hello() {
        System.out.println(armor.getDesc());
    }
}
